<template>
	<!-- 通讯录 -->
	<view class="page">
		<myNavBar title="通讯录"></myNavBar>
		<view class="tab-page friend">
			<view class="nav-bar">
				<view class="nav-search">
					<uni-search-bar @focus="onFocusSearch" cancelButton="none" placeholder="点击搜索好友"></uni-search-bar>
				</view>
				<view class="nav-add">
					<!-- 更多 -->
					<rudon-rowMenuDotDotDot :localdata="options" @change="menuAction($event)">
						<image src="../../static/image/more.png" style="width: 30rpx;height: 30rpx;margin-right: 10rpx;"></image>
					</rudon-rowMenuDotDotDot>
				</view>
			</view>

			<view class="pagewrap">
				<uni-collapse>
					<uni-collapse-item title="我的好友" :show-animation="true" :open="true">
						<scroll-view class="scroll-bar" scroll-with-animation="true" scroll-y="true">
							<!-- 先展示在线好友-->
							<view v-for="(friend,index) in friends" :key="index">
								<friend-item v-if="!friend.delete&&friend.online" :friend="friend"></friend-item>
							</view>
							<!-- 再展示离线好友-->
							<view v-for="(friend,index) in friends" :key="index">
								<friend-item v-if="!friend.delete&&!friend.online" :friend="friend"></friend-item>
							</view>
						</scroll-view>
					</uni-collapse-item>
					<uni-collapse-item title="我的群聊" :show-animation="true" :open="true">
						<scroll-view class="scroll-bar" scroll-with-animation="true" scroll-y="true">
							<view v-for="group in $store.state.groupStore.groups" :key="group.id">
								<group-item v-if="!group.quit" :group="group"></group-item>
							</view>
						</scroll-view>
					</uni-collapse-item>
				</uni-collapse>
			</view>

			<!-- 		<view class="friend-tip" v-if="friends.length==0">
				温馨提示：您现在还没有任何好友，快点击右上方'+'按钮添加好友吧~
			</view>
			<view class="friend-items" v-else>
				<scroll-view class="scroll-bar" scroll-with-animation="true" scroll-y="true">
					<view v-for="(friend,index) in friends" :key="index">
						<friend-item v-if="!friend.delete&&friend.online" :friend="friend"></friend-item>
					</view>
					<view v-for="(friend,index) in friends" :key="index">
						<friend-item v-if="!friend.delete&&!friend.online" :friend="friend"></friend-item>
					</view>
				</scroll-view>
			</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				options: [{
						value: 1,
						text: "添加好友",
					},
					{
						value: 2,
						text: "发起群聊",
					},
					{
						value: 3,
						text: "新的朋友",
					},
					{
						value: 4,
						text: "取消",
					},
				],
			}
		},
		methods: {
			menuAction(action) {
				if (action == "") return;
				if (action == 1) {
					// 添加好友
					this.onAddNewFriends()
				} else if (action == 2) {
					// 发起群聊
					uni.navigateTo({
						url: "/pages/group/group-edit"
					})
				} else if (action == 3) {
					// 新的朋友
				}
			},
			onFocusSearch() {
				uni.navigateTo({
					url: "/pages/friend/friend-search"
				})
			},
			onAddNewFriends() {
				uni.navigateTo({
					url: "/pages/friend/friend-add"
				})
			}
		},
		computed: {
			friends() {
				return this.$store.state.friendStore.friends;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.friend {
		position: relative;
		border: #dddddd solid 1px;
		display: flex;
		flex-direction: column;

		.friend-tip {
			position: absolute;
			top: 400rpx;
			padding: 50rpx;
			text-align: center;
			line-height: 50rpx;
			text-align: left;
			color: darkblue;
			font-size: 30rpx;
		}

		.nav-bar {
			margin: 5rpx;
			display: flex;
			align-items: center;
			background-color: white;

			.nav-search {
				flex: 1;
			}

			.nav-add {
				line-height: 56px;
				cursor: pointer;
			}
		}

		.friend-items {
			flex: 1;
			padding: 0;
			border: #dddddd solid 1px;
			overflow: hidden;
			position: relative;

			.scroll-bar {
				height: 100%;
				padding: 10rpx 25rpx;
			}
		}
	}

	.pagewrap {
		height: calc(100vh - 140px);
		overflow-y: scroll;
	}
</style>